
import 'dart:collection';
import 'dart:convert';

import 'package:ai/response/BaseResponse.dart';

import '../response/TextAppResponse.dart';
import '../util/DioUtil.dart';

class TextCreateService{

  Future<AppItem> init(int appId) async {

    Map<String, dynamic> params = {
      'appId': "$appId",
    };
    
    var response = await DioUtil().post('/textApp/detail',data: params);
    var homeResponse = TextAppResponse.fromJson(response.data);
    return homeResponse.data;
  }

  Future<BaseResponse> create(AppItem appItem) async {
    Map<String, dynamic> params = {
      'textAppId': "${appItem.id}",
    };
    Map<String, dynamic> params1 = HashMap();
    for(int i=0;i<appItem.formList.length;i++){
      var formItem = appItem.formList[i];
      params1.addAll({
        formItem.label: formItem.value
      });
    }
    params.addAll({
      "params": json.encode(params1),
    });
    
    
    var response = await DioUtil().post('/member/write/text',data: params);
    var baseResponse = BaseResponse.fromJson(response.data);
    return baseResponse;
  }
}